package com.zy.socket.url;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;

/**
 * @Author Gong
 * @Description
 * @dATE 2021/12/19 17:19
 **/
public class Url {
    public static void main(String[] args) {

        String urlAddress = "https://www.baidu.com/img/baidu_jgylogo3.gif";
        InputStream is = null;
        OutputStream os = null;
        URL url = null;
        try {
            url = new URL(urlAddress);
//            URLConnection urlConnection = url.openConnection();
//            OutputStream outputStream = urlConnection.getOutputStream();
            is = url.openStream();
            os = new FileOutputStream("d:/temp/copy.gif");
            byte[] bys = new byte[1024];
            int len = 0;
            while((len = is.read(bys))!=-1){
                os.write(bys, 0, len);
            }
        } catch(Exception e){
            e.printStackTrace();
        }

//        String urlAddress = "https://www.baidu.com/img/baidu_jgylogo3.gif?name=zhangsan&id=154";
//        URL url = null;
//        try {
//            url = new URL(urlAddress);
//// 协议名
//            System.out.println("协议名:"+url.getProtocol());
//// 主机号
//            System.out.println("主机号:"+url.getHost());
//// 端口号
//            System.out.println("端口号:"+url.getPort());
//// 文件路径
//            System.out.println("文件路径:"+url.getPath());
//// 文件名
//            System.out.println(" 文件名:"+url.getFile());
//// 文件相对位置
//            System.out.println("文件相对位置:"+url.getRef());
//// 参数列表
//            System.out.println("查询名:"+url.getQuery());
//        } catch (MalformedURLException e) {
//        }

    }
}
